package com.banksoft.cps.service.impl;

import com.banksoft.cps.bean.MonitorVideo;
import com.banksoft.cps.bean.query.MonitorVideoQuery;
import com.banksoft.cps.dao.MonitorVideoDao;
import com.banksoft.cps.service.MonitorVideoService;
import com.banksoft.cps.util.UUIDFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by rongzhao.zhu on 2018/8/28.
 */
@Service
public class MonitorVideoServiceImpl implements MonitorVideoService {

    @Autowired
    private MonitorVideoDao monitorVideoDao;

    @Override
    public List<MonitorVideo> list(MonitorVideoQuery query) {
        return monitorVideoDao.list(query);
    }

    @Override
    public long count(MonitorVideoQuery query) {
        return monitorVideoDao.count(query);
    }

    @Override
    public void save(MonitorVideo bean) {
        if(StringUtils.isNotBlank(bean.getId())){
            monitorVideoDao.update(bean);
        }else {
            bean.setId(UUIDFactory.random());
            bean.setCreateTime(System.currentTimeMillis());
            monitorVideoDao.insert(bean);
        }
    }

    @Override
    public void delete(String id) {
        monitorVideoDao.delete(id);
    }

    @Override
    public MonitorVideo findById(String id) {
        if(StringUtils.isNotBlank(id)){
            MonitorVideoQuery query = new MonitorVideoQuery();
            query.setId(id);
            List<MonitorVideo>  list = monitorVideoDao.list(query);
            if(!list.isEmpty()){
                return list.get(0);
            }
        }
        return null;
    }
}
